import numpy as np


def ini_per(x,y,eta):
    weight=np.zeros(x.shape[1])
    b=0
    num=0
    mistake=True

    while mistake==True:#如果分类有错误才修改参数
        mistake=False
        for i in range(x.shape[0]):
            if y[i]*(np.dot(weight,x[i])+b)<=0:
                weight=weight+eta*y[i]*x[i]
                b=b+eta*y[i]
                num+=1
                print(weight,b)
                mistake=True
                break
    print(num)

if __name__=='__main__':
    x=np.array([[3,3],[4,3],[1,1]])
    y=np.array([1,1,-1])
    ini_per(x,y,1)



